package com.test.clyq.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import com.test.Constants;
import com.test.clyq.entity.Category;
import com.test.clyq.entity.DataPermission;
import com.test.clyq.entity.Users;
import com.test.clyq.form.CategoryForm;
import com.test.clyq.service.CategoryService;
import com.test.clyq.service.DataPermissionService;
import com.test.json.JsonTree;
import com.test.json.JsonUtil;
import com.test.util.FileUtils;
import com.test.util.FormatExceptionStack;
import com.test.util.ObjectUtils;
import com.test.util.Pagination;
import com.test.util.SessionUtil;
import com.test.util.StringUtils;
import com.test.webapp.action.BaseAction;

/**
 * CategoryAction. <br>
 * 栏目管理.
 * <p>
 * Copyright: Copyright (c) 2010-4-17 下午04:49:16
 * <p>
 * Company: 北京宽连十方数字技术有限公司
 * <p>
 * Author: liuxl@c-platform.com
 * <p>
 * Version: 1.0
 * <p>
 */
public class CategoryAction extends BaseAction {

	/**
	 * 获得登录用户的栏目列表
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 栏目列表
	 * @throws IOException
	 */
	public ActionForward categoryList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得栏目列表start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		try {
			String start = request.getParameter("start");
			if (!StringUtils.isEmpty(start)) {
			} else {
				start = 0 + "";
			}
			int currpageNo = 1;
			if (Integer.parseInt(start) / 20 != 0) {
				currpageNo = Integer.parseInt(start) / 20 + 1;// 当前页码
			}
			Pagination pagination = new Pagination(currpageNo, 20);// 设置分页参数（页码和每页显示记录条数）
			List<Category> list = null;
			int totalCount = 1;
			list = categoryService.getCategorys(); // 获取栏目列表
			totalCount = pagination.getTotalRows();
			String jsonStr = JsonUtil.getJsonStr(list, null, totalCount);
			print(response, jsonStr, null, null);
			this.log.debug("获得栏目列表成功");
			this.log.info("获得栏目列表end");
		}
		catch (Exception e) {
			this.log.error("获得栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 获得下级栏目列表
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 栏目列表
	 * @throws IOException
	 */
	public ActionForward categoryListByPId(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得下级栏目列表start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		String pId = getParameter(request, "pId"); // 标识 mark 不为空
		try {
			List<Category> list = null;
			list = categoryService.getCategoryListByParentId(Long.valueOf(pId)); // 获取栏目列表
			String jsonStr = JsonUtil.getJsonStr(list, null, 100);
			print(response, jsonStr, null, null);
			this.log.debug("获得栏目列表成功");
			this.log.info("获得栏目列表end");
		}
		catch (Exception e) {
			this.log.error("获得栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 获得登录用户的栏目树
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 栏目列表
	 * @throws IOException
	 */
	public ActionForward categoryNoCheckTree(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得栏目树列表start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		try {
			List<Category> list = categoryService.getCategorys();
			String str = JsonTree.getJsonStringByList(list, "categoryName", "categoryParentId", false);
			print(response, str, null, null);
			this.log.debug("获得栏目列表成功");
			this.log.info("获得栏目列表end");
		}
		catch (Exception e) {
			this.log.error("获得栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 获得专题栏目树
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 栏目列表
	 * @throws IOException
	 */
	public ActionForward categoryZhuanTiTree(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得专题栏目树start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		try {
			List<Category> list = categoryService.getCategorys(-1);
			String str = JsonTree.getJsonStringByList(list, "categoryName", "categoryParentId", false);
			print(response, str, null, null);
			this.log.debug("获得专题栏目树列表成功");
			this.log.info("获得专题栏目树列表end");
		}
		catch (Exception e) {
			this.log.error("获得专题栏目树:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 获得登录用户的栏目树
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 栏目列表
	 * @throws IOException
	 */
	public ActionForward categoryNoCheckTreeById(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得栏目树列表start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		String cId = request.getParameter("cId");
		try {
			if (StringUtils.isNumeric(cId)) {
				List<Category> list = categoryService.getCategoryListByParentId(Long.valueOf(cId));
				String str = com.test.json.JsonTree.getJsonNoCheckStringByList(list, "categoryName", "categoryParentId", Long.valueOf(cId));
				this.log.debug("获得栏目列表成功");
				this.log.info("获得栏目列表end");
				print(response, str, null, null);
			} else {
				print(response, false);
			}
		}
		catch (Exception e) {
			this.log.error("获得栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 获得登录用户的栏目树
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 栏目列表
	 * @throws IOException
	 */
	public ActionForward categoryTree(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得栏目树列表start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		try {
			List<Category> list = categoryService.getCategorys();
			String str = com.test.json.JsonTree.getJsonStringByList(list, "categoryName", "categoryParentId");
			this.log.debug("获得栏目列表成功");
			this.log.info("获得栏目列表end");
			print(response, str, null, null);
		}
		catch (Exception e) {
			this.log.error("获得栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	// /**
	// * 根据模板id获取栏目树
	// *
	// * @param mapping
	// * @param form
	// * @param request
	// * @param response
	// * @return 栏目列表
	// * @throws IOException
	// */
	// @SuppressWarnings("unchecked")
	// public ActionForward categoryTreeBytId(ActionMapping mapping,
	// ActionForm form, HttpServletRequest request,
	// HttpServletResponse response) throws IOException {
	// this.log.info("获得栏目树列表start");
	// CategoryService categoryService = (CategoryService)
	// getBean("categoryService");
	// String cId = request.getParameter("tId");
	// try {
	// if (StringUtils.isNumeric(cId)) {
	// List<Category> list = categoryService
	// .getCategoryListByParentId(Long.valueOf(cId));
	// String str = com.test.json.JsonTree
	// .getJsonNoCheckStringByList(list, "categoryName",
	// new HashSet(), null);
	// this.log.debug("获得栏目列表成功");
	// this.log.info("获得栏目列表end");
	// print(response, str, null, null);
	// } else {
	// print(response, false);
	// }
	// } catch (Exception e) {
	// this.log
	// .error("获得栏目:失败 " + FormatExceptionStack.formatException(e));
	// print(response, false);
	// }
	// return null;
	// }

	/**
	 * 删除栏目
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward delCategory(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("删除栏目start");
		String uId = request.getParameter("categoryId");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		Users user = SessionUtil.getUserFromSession(request);
		try {
			boolean bl = categoryService.delCategoryById(Long.valueOf(uId), user);
			StringBuilder sb = new StringBuilder();
			sb.append("{");
			if (bl) {
				sb.append("success:true");
			} else {
				sb.append("error:error");
			}
			sb.append("}");
			String dd = sb.toString();
			this.log.debug("删除栏目成功");
			this.log.info("删除栏目end");
			print(response, dd, null, null);
		}
		catch (Exception e) {
			this.log.error("删除栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 修改栏目
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward editCategory(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("修改栏目start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		String categoryId = request.getParameter("uId");
		try {
			Category category = categoryService.getCategoryById(Long.valueOf(categoryId));
			this.log.debug("修改栏目成功");
			this.log.info("修改栏目end");
			String fragStr = "{results:[{" + category.toJSON() + "}]}";
			print(response, fragStr, null, null);
		}
		catch (Exception e) {
			this.log.error("修改栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 修改栏目
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward editCategoryById(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("修改栏目start");
		// CategoryService categoryService = (CategoryService)
		// getBean("categoryService");
		// String categoryId = request.getParameter("categoryId");
		try {
			// Category category =
			// categoryService.getCategoryById(Long.valueOf(categoryId));
			String fragStr = "";// category.getEntityTypeId();
			print(response, fragStr, null, null);
		}
		catch (Exception e) {
			this.log.error("修改栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 获得栏目一级树
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 栏目列表
	 * @throws IOException
	 */
	public ActionForward getFirstCategoryTree(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得栏目树列表start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		String mark = getParameter(request, "mark"); // 标识 mark 不为空
		Users user = SessionUtil.getUserFromSession(request);
		// 返回一级栏目列表
		try {
			String str = null;
			List<Category> list = categoryService.getFirstLevelCategoryList(user.getUsersWebsite(), new Pagination(1, 100));
			if (!StringUtils.isEmpty(mark)) {
				str = JsonUtil.getJsonStr(list, null, 100);
			} else {
				str = JsonTree.getJsonStringByList(list, "categoryName", "categoryParentId", false);
			}

			print(response, str, null, null);
			this.log.debug("获得栏目列表成功");
			this.log.info("获得栏目列表end");
		}
		catch (Exception e) {
			this.log.error("获得栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 获得登录用户的栏目树
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 栏目列表
	 * @throws IOException
	 */
	public ActionForward getUserCategoryTree(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得栏目树列表start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		DataPermissionService dataPermissionService = (DataPermissionService) getBean("dataPermissionService");
		Users user = SessionUtil.getUserFromSession(request);
		try {
			List<Category> list = null;
			if (user.getIsUsersAdmin() == 1) {
				list = categoryService.getCategorys(user.getUsersWebsite());
			} else {
				list = new ArrayList<Category>();
				Set<DataPermission> dataPermissionSet = dataPermissionService.getDatePermissionByUserIdAndCategoryId(null, user.getId());
				for (DataPermission permission : dataPermissionSet) {
					Category category = categoryService.getCategoryById(permission.getDatePermissionCategoryId());
					if (!ObjectUtils.isNull(category)) {
						// 添加website判断
						if (user.getUsersWebsite() == category.getWebsite()) {
							list.add(category);
						}
					}
				}
			}

			String str = JsonTree.getJsonStringByList(list, "categoryName", "categoryParentId", false);
			print(response, str, null, null);
			this.log.debug("获得栏目列表成功");
			this.log.info("获得栏目列表end");
		}
		catch (Exception e) {
			this.log.error("获得栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * mms排序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward mmsOrder(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("mms排序栏目start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		Users user = SessionUtil.getUserFromSession(request);
		String categoryId = getParameter(request, "categoryId");
		try {
			if (!ObjectUtils.isNull(user) && !StringUtils.isEmpty(categoryId) && StringUtils.isNumeric(categoryId)) {
				Category category = categoryService.getCategoryById(Long.valueOf(categoryId));
				if (!ObjectUtils.isNull(category)) {
					String location = getParameter(request, "mmsLocation");
					if (!StringUtils.isEmpty(location)) {
						category.setMmsLocation(Integer.valueOf(location));
					}
					categoryService.saveOrUpdate(category, user);
					this.log.debug("mms排序栏目成功");
					this.log.info("mms排序栏目end");
					print(response, true);
				}
			}
		}
		catch (Exception e) {
			this.log.error("mms排序栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 排序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward order(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException {
		this.log.info("排序栏目start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		Users user = SessionUtil.getUserFromSession(request);
		String categoryId = getParameter(request, "categoryId");
		try {
			if (!ObjectUtils.isNull(user) && !StringUtils.isEmpty(categoryId) && StringUtils.isNumeric(categoryId)) {
				Category category = categoryService.getCategoryById(Long.valueOf(categoryId));
				if (!ObjectUtils.isNull(category)) {
					String location = getParameter(request, "location");
					if (!StringUtils.isEmpty(location)) {
						category.setLocation(Integer.valueOf(location));
					}
					categoryService.saveOrUpdate(category, user);
					this.log.debug("排序栏目成功");
					this.log.info("排序栏目end");
					print(response, true);
				}
			}
		}
		catch (Exception e) {
			this.log.error("排序栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 推荐
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward recommend(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("置顶栏目start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		Users user = SessionUtil.getUserFromSession(request);
		String categoryId = getParameter(request, "categoryId");
		try {
			if (!ObjectUtils.isNull(user) && !StringUtils.isEmpty(categoryId) && StringUtils.isNumeric(categoryId)) {
				Category category = categoryService.getCategoryById(Long.valueOf(categoryId));
				if (!ObjectUtils.isNull(category)) {
					Integer push = category.getIsPush();
					if (push == 0) {
						category.setIsPush(1);
					} else {
						category.setIsPush(0);
					}
					categoryService.saveOrUpdate(category, user);
					this.log.debug("推荐栏目成功");
					this.log.info("推荐栏目end");
					print(response, true);
				}
			}
		}
		catch (Exception e) {
			this.log.error("推荐栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 推荐
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward Recommend(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("置顶栏目start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		Users user = SessionUtil.getUserFromSession(request);
		String categoryId = getParameter(request, "categoryId");
		try {
			if (ObjectUtils.isNull(user) && !StringUtils.isEmpty(categoryId) && StringUtils.isNumeric(categoryId)) {
				Category category = categoryService.getCategoryById(Long.valueOf(categoryId));
				if (!ObjectUtils.isNull(category)) {
					Integer push = category.getIsPush();
					if (push == 0) {
						category.setIsPush(1);
					} else {
						category.setIsPush(0);
					}
					categoryService.saveOrUpdate(category, user);
					this.log.debug("推荐栏目成功");
					this.log.info("推荐栏目end");
					print(response, true);
				}
			}
		}
		catch (Exception e) {
			this.log.error("推荐栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 保存栏目
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward saveCategory(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("保存栏目start");
		CategoryForm categoryForm = (CategoryForm) form;
		Category category = new Category();
		String pId = request.getParameter("categoryParentId"); // 类别父id
		String isPush = request.getParameter("isPush"); // 是否推荐
		String isPublic = request.getParameter("isPublic");// 是否定制可见
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		Users user = SessionUtil.getUserFromSession(request);
		try {
			if (!StringUtils.isEmpty(isPush)) {
				category.setIsPush(Integer.valueOf(isPush));
			}
			if (!StringUtils.isEmpty(isPublic)) {
				category.setIsPublic(Integer.valueOf(isPublic));
			}
			String picPath = saveObject(categoryForm.getFile());
			if (!StringUtils.isEmpty(picPath)) {
				category.setCategoryImageUrl(picPath);
			}
			category.setCategoryImgToUrl(getParameter(request, "categoryImgToUrl"));
			category.setCategoryName(categoryForm.getCategoryName());
			category.setCategoryDesc(categoryForm.getCategoryDesc());
			if (!StringUtils.isEmpty(pId) && !pId.equals("root")) {
				category.setCategoryParentId(Long.valueOf(pId));
			} else {
				category.setCategoryParentId(new Long(0));
			}
			category.setWebsite(user.getUsersWebsite());
			categoryService.saveOrUpdate(category, user);
			print(response, true);
			this.log.debug("保存栏目成功");
			this.log.info("保存栏目end");
		}
		catch (Exception e) {
			this.log.error("保存栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 保存专题栏目
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward saveZhuanTiCategory(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("保存专题栏目start");
		CategoryForm categoryForm = (CategoryForm) form;
		Category category = new Category();
		String pId = request.getParameter("categoryParentId"); // 类别父id
		String templateType = request.getParameter("templateType"); // 模板类型
		// String isPublic = request.getParameter("isPublic");// 是否定制可见
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		Users user = SessionUtil.getUserFromSession(request);
		try {

			if (!StringUtils.isEmpty(templateType)) {
				category.setTemplateType(Integer.valueOf(templateType));
			}
			category.setIsPush(0);
			category.setIsPublic(0);
			// 专题栏目
			category.setZhuanTi(1);
			String picPath = saveObject(categoryForm.getFile());
			if (!StringUtils.isEmpty(picPath)) {
				category.setCategoryImageUrl(picPath);
			}
			category.setCategoryImgToUrl(getParameter(request, "categoryImgToUrl"));
			category.setCategoryName(categoryForm.getCategoryName());
			category.setCategoryDesc(categoryForm.getCategoryDesc());
			if (!StringUtils.isEmpty(pId) && !pId.equals("root")) {
				category.setCategoryParentId(Long.valueOf(pId));
			} else {
				category.setCategoryParentId(new Long(0));
			}
			category.setWebsite(user.getUsersWebsite());
			categoryService.saveOrUpdate(category, user);
			print(response, true);
			this.log.debug("保存专题栏目成功");
			this.log.info("保存专题栏目end");
		}
		catch (Exception e) {
			this.log.error("保存专题栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 上传图片
	 * 
	 * @param fileForm
	 * @param request
	 * @return
	 */

	private String saveObject(FormFile file) {
		if (file == null) {
			return null;
		} else {
			String dir = (String) Constants.settings.get("UPLOAD_DIR");
			String imageType[] = { "jpeg", "gif", "bmp", "BMP", "png", "jpg", "JPG", "GIF" };
			String fileName = file.getFileName();
			int ff = fileName.indexOf(".");
			String contentType = fileName.substring(ff + 1);
			String fileType = contentType;
			for (int j = 0; j < imageType.length; j++) {
				if (imageType[j].equals(fileType)) {
					String path;
					try {
						// 调用图片的上传的方法,并且返回上传服务器的路径
						path = FileUtils.upload(dir, file);
						return path;
					}
					catch (Exception e) {
						e.printStackTrace();
						return null;
					}
				}
			}
		}
		return null;
	}

	/**
	 * 更新栏目
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward updateCategory(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("更新栏目start");
		CategoryForm categoryForm = (CategoryForm) form;
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		Users user = SessionUtil.getUserFromSession(request);
		String isPush = request.getParameter("isPush");
		String isPublic = request.getParameter("isPublic");// 是否定制可见
		try {
			Category category = categoryService.getCategoryById(categoryForm.getCategoryId());
			if (category != null) {
				if (!StringUtils.isEmpty(isPush)) {
					category.setIsPush(Integer.valueOf(isPush));
				}
				if (!StringUtils.isEmpty(isPublic)) {
					category.setIsPublic(Integer.valueOf(isPublic));
				}
				String picPath = saveObject(categoryForm.getFile());
				if (!StringUtils.isEmpty(picPath)) {
					category.setCategoryImageUrl(picPath);
				}
				category.setCategoryImgToUrl(getParameter(request, "categoryImgToUrl"));
				category.setCategoryName(categoryForm.getCategoryName());
				category.setCategoryDesc(categoryForm.getCategoryDesc());
				category.setEntityItemSet(category.getEntityItemSet());
				categoryService.saveOrUpdate(category, user);
			}
			print(response, true);
			this.log.debug("更新栏目成功");
			this.log.info("更新栏目end");
		}
		catch (Exception e) {
			this.log.error("保存栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 可见
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException {
		this.log.info("可见栏目start");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		Users user = SessionUtil.getUserFromSession(request);
		String categoryId = getParameter(request, "categoryId");
		try {
			if (ObjectUtils.isNull(user) && !StringUtils.isEmpty(categoryId) && StringUtils.isNumeric(categoryId)) {
				Category category = categoryService.getCategoryById(Long.valueOf(categoryId));
				if (!ObjectUtils.isNull(category)) {
					Integer ispublic = category.getIsPublic();
					if (ispublic == 0) {
						category.setIsPublic(1);
					} else {
						category.setIsPublic(0);
					}
					categoryService.saveOrUpdate(category, user);
					this.log.debug("可见栏目成功");
					this.log.info("可见栏目end");
					print(response, true);
				}
			}
		}
		catch (Exception e) {
			this.log.error("可见栏目:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}
}
